package test;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.sql.DataSource;

//import org.apache.taglibs.standard.lang.jstl.test.Bean1;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.itcast.bean.product.ProductType;
import com.itcast.service.product.ProductTypeService;

public class MyJUnit {

	
	@Test
	public void runTest(){
		EntityManagerFactory factory= Persistence.createEntityManagerFactory("itcast");
		EntityManager em=factory.createEntityManager();
		em.getTransaction().begin();
		em.persist(new ProductType());
		em.getTransaction().commit();
		em.close();
		factory.close();
	}
	@Test
	public void testMySqlDriver() throws SQLException, ClassNotFoundException{
		//Class.forName("com.mysql.jdbc.Driver");
		Class.forName("org.gjt.mm.mysql.Driver");
		Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf8","root","803129");
		
		String sql="insert into ProductType(name ,note ,visible) values('日','haha',1)";
		Statement stat=con.createStatement();
		stat.execute(sql);
		
		stat.close();
		con.close();
		System.out.println(con);
	}


}
